<form class="layui-form " action="" lay-filter="dataForm" id="withdrawDiv" {$admin_info.openid?  '':'style="display: none;"' } >
    <input type="hidden" name="id">
    <div class="layui-form-item"  >
        <label class="layui-form-label" style="width:100px;">账户余额</label>
        <div class="layui-input-block">
            <label class="layui-form-label" style="text-align: left;padding-left: 0; width:auto;">
                <span style="color: #f00;font-weight: bold">{$admin_info.balance|default="0"} 元</span>
            </label>
        </div> 
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px;">提现金额</label>
        <div class="layui-input-inline">
            <input type="text" name="money" lay-verify="required" autocomplete="off" placeholder="请输入金额" class="layui-input">
        </div>        
        <div class="layui-form-mid layui-word-aux">元</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="dataSubmit">确认提现</button>
        </div>
    </div>
</form>

<div id="qrcodeDiv" {$admin_info.openid?  'style="display: none;"':'' }>
        <div id="bindone" {$admin_info.bind_phone?  'style="display: none;"':'' }>
        第一步
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px;">绑定手机号</label>
            <div class="layui-input-inline">
                <label class="layui-form-label" style="text-align: left;padding-left: 0; width:auto;">
                    {$admin_info.phone}
                </label>
            </div>         
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px;">验证码</label>
            <div class="layui-input-inline">
                <input type="text" name="vcode" id="vcode" lay-verify="required"autocomplete="off" placeholder="请输入验证码" class="layui-input">
            </div>         
            <button class="layui-btn  layui-btn-primary" id="getVcode" type="button">获取验证码</button>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" id="confirm" type="button" lay-filter="dataSubmit">确认绑定</button>
            </div>
        </div>
    </div>
    <div id="bindtwo" {$admin_info.bind_phone?  '':'style="display: none;"' }>
        第二步
        <div>请先扫码绑定微信</div>
        <img src="/index/getqrcode?admin_id={$admin_info.id}"/>
    </div>
</div>
<script>
    layui.use(['form', 'http'], function () {
        var form = layui.form;
        var http = layui.http;
        var $ = layui.$;

        //表单初始赋值
        form.val('dataForm', {
            "id": "{$id}",
        })
        

        $("#getVcode").click(function(){
            http.post('/withdraw/sendVerificationCode', {phone:$("#getPhone").val()}, function (res) {
                if (res.code == 0) {
                    $("#getVcode").attr("disabled", true).addClass("layui-disabled")
                    var time = 59
                    var vcodesi = setInterval(function(){
                        if(time<=1){
                            $("#getVcode").html("获取验证码").attr("disabled", false).removeClass("layui-disabled")
                            clearInterval(vcodesi)
                        }else
                            $("#getVcode").html("重新获取("+time+")")
                        time--;
                    },1000)
                }
            }, $(this))
        })
        
        $("#confirm").click(function(){
            http.post('/withdraw/bindPhone', {phone:$("#getPhone").val(),code:$("#vcode").val()}, function (res) {
                if (res.code == 0) {
                    $("#bindone").hide();
                    $("#bindtwo").show();
                    var si = setInterval(function(){
                        $.post('/index/getwxlogin', {admin_id:'{$admin_info.id}'}, function(res) {
                            if (res.code == 0) {
                                $("#qrcodeDiv").hide();
                                $("#withdrawDiv").show();
                                layer.msg('微信绑定成功', {
                                    offset: '45px',
                                    icon: 1,
                                    time: 800,
                                });
                                clearInterval(si)
                            }
                        })
                    },2000) 
                }
            }, $(this))
        })
        //监听提交
        form.on('submit(dataSubmit)', function (data) {
            http.post('/withdraw/withdraw', data.field, function (res) {
                if (res.code == 0) {
                    parent.layui.table.reload('dataTable');
                    parent.layer.closeAll('page');
                }
            }, $(this))
            return false;
        })
    })
</script>